﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Client.Service;

namespace Client
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            if (string.IsNullOrEmpty(txtName.Text))
            {
                lblNameError.Content = "The Name field is required!";
                return;
            }
            this.lblNameError.Content = "";

            if (string.IsNullOrEmpty(txtEmail.Text))
            {
                lblEmailError.Content = "The Email field is required!";
                return;
            }
            this.lblEmailError.Content = "";

            var contact = new Contact
                {
                    Name = this.txtName.Text,
                    Email = this.txtEmail.Text,
                    PhoneNumber = this.txtPhone.Text
                };

            var service = new ContactService();

            try
            {
                service.AddContact(contact);
                MessageBox.Show("New contact was added successfully!");
            }
            catch (Exception ex)
            {
                lblEmailError.Content = ex.Message;
            }
        }
    }
}
